<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    @close="closeDialog()"
    :visible.sync="visible">
    <configgather-component ref="addOrUpdateConfigGather" @refreshAddFtpStatus="refreshAddFtpStatus" @addFtpSussess="addFtpSussess" @refreshConfigGatherDataList="refreshConfigGatherDataList" @configGatherDisvisible="configGatherDisvisible"></configgather-component>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="backToGather()" v-if="addFtpStatus">返回</el-button>
      <el-button type="primary" @click="checkFtpStatus()" v-if="canSubmit && addFtpStatus">FTP状态检查</el-button>
      <el-button type="primary" @click="ftpDataFormSubmit()" v-if="canSubmit && addFtpStatus">添加FTP</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit && !addFtpStatus">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    
    import ConfiggatherComponent from './configgather-component'


    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        addFtpStatus: false,
        dataForm: {},
      }
    },
    components: {
      ConfiggatherComponent
    },
    methods: {
      configGatherDisvisible () {
        this.visible = false
      },
      addFtpSussess () {
        this.backToGather()
      },
      refreshConfigGatherDataList () {
        this.$emit('refreshDataList')
      },
      refreshAddFtpStatus (status) {
        this.addFtpStatus = status
      },
      backToGather () {
        this.addFtpStatus = false
        this.$refs.addOrUpdateConfigGather.ftpVisible = false
      },
      init (id) {
        this.visible = true;
        this.canSubmit = true;
        this.dataForm.id = id
        this.$nextTick(() => {
          this.$refs.addOrUpdateConfigGather.init(id)
        })
      },
      checkFtpStatus () {
        this.$refs.addOrUpdateConfigGather.checkFtpStatus()
      },
      ftpDataFormSubmit () {
        this.$refs.addOrUpdateConfigGather.ftpDataFormSubmit()
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs.addOrUpdateConfigGather.dataFormSubmit()
      },
      //重置表单
      closeDialog() {
        this.dataForm.id = ''
        this.$refs.addOrUpdateConfigGather.closeDialog()
      }
    }
  }
</script>
